/*
 * graph.h
 *
 *  Created on: Aug 6, 2013
 *      Author: cdoar
 */

#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
#include<math.h>
#include<float.h>
#include<stdarg.h>

#define num_char 500 /* # of characters in command  */
#define isType(x,y) !strcmp(x,y)
#define ADD_VERTEX "add_vertex"
#define ADD_EDGE "add_edge"
#define ALLOCATED 0
#define ALLOC_ERR 1
#define NOT_ALLOCATED NULL
#define MALLOC_ERROR "Error: standard function malloc has failed"
#define CALLOC_ERROR "Error: standard function calloc has failed"
#define REALLOC_ERROR "Error: standard function realloc has failed"
#define CHECK_ALLOC(x,y) if(x == NULL){perror(y);freeGraph();return;} /*check if memory allocation is successful if not terminate.*/
#define CHECK_ALLOC_VTX(x,y,a,b) if(x == NULL){perror(y);freeVertex(a,b);freeGraph();return;} /*check if memory allocation is successful if not terminate.*/
#define CHECK_ALLOC_DOWNLOAD(x,y,a,b,c) if(x == NULL){perror(y);quit_download(a,b,c);return;}


struct element_s {
   int unsigned id_vetex;
   double weight;
   struct element_s   *next;
};

typedef   struct element_s *  element;

struct  linked_list_s{
	element head ;
	element tail ;
};

typedef   struct linked_list_s *  linked_list;

struct vertex_s {
   int unsigned ID;
   int unsigned cluster;
   char name [num_char];
   linked_list edges;
};

typedef struct  vertex_s * vertex;

int only_whitespaces(char * str);
int getCommand(char *, char *,char *,char *,char *);
void executeCommand(char *,char *,char *,char *,int);
void addVertex(char *);
void addEdge(char *, char *,char *);


void download(char *, char *);
void freeList(linked_list);
int contains(linked_list,linked_list,unsigned,unsigned);
unsigned toUnsigned(char *);
double toDouble(char *);
void printer(unsigned, unsigned, unsigned, int *);
int idCheck(unsigned);
int validateInput(int,int,char*);
void freeVertex(vertex, int);
void quit_download(int*,int*,linked_list);
int add(linked_list,int,double);
int generate(FILE *);
void freeGraph();
int uniqueName(char *);
void printGraph();
int validWeight(char *);
